var gulp   = require('gulp'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
    shell  = require('gulp-shell');
/*
gulp.task('browserify-admin', shell.task([
    'sh browserify.admin.sh'
]));

gulp.task('uglify-admin', ['browserify-admin'], function () {
    gulp.src('./target/admin.js')
        .pipe(uglify())
        .pipe(rename('admin.js'))
        .pipe((gulp.dest('./www/admin/')));
});

gulp.task('browserify-sales', shell.task([
    'sh browserify.sales.sh'
]));

gulp.task('uglify-sales', ['browserify-sales'], function () {
    gulp.src('./target/sales.js')
        .pipe(uglify())
        .pipe(rename('sales.js'))
        .pipe((gulp.dest('./www/sales/')));
});


gulp.task('browserify-insurance', shell.task([
    'sh browserify.insurance.sh'
]));

gulp.task('uglify-insurance', ['browserify-insurance'], function () {
    gulp.src('./target/insurance.js')
        .pipe(uglify())
        .pipe(rename('insurance.js'))
        .pipe((gulp.dest('./www/insurance/')));
});

gulp.task('uglify-all', ['uglify-admin','uglify-insurance','uglify-sales']);

gulp.task('browserify-all', ['browserify-admin','browserify-insurance','browserify-sales']);


gulp.task('watch', function () {
    gulp.watch('./js-app/sales/controllers/*.js', ['browserify-sales', 'uglify-sales']);
    gulp.watch('./js-app/sales/*.js', ['browserify-sales', 'uglify-sales']);

    gulp.watch('./js-app/admin/controllers/*.js', ['browserify-admin', 'uglify-admin']);
    gulp.watch('./js-app/admin/*.js', ['browserify-admin', 'uglify-admin']);

    gulp.watch('./js-app/*.js', ['browserify-all', 'uglify-all']);

    gulp.watch('./js-app/directives/*.js', ['browserify-all', 'uglify-all']);
});
*/

gulp.task('browserify', shell.task([
    'sh browserify.sh'
]));

gulp.task('uglify', ['browserify'], function () {
    gulp.src('./target/app.js')
        .pipe(uglify())
        .pipe(rename('app.js'))
        .pipe((gulp.dest('./www/')));
});

gulp.task('watch', function () {
    gulp.watch('./js-app/**/*.js', ['browserify', 'uglify']);
    gulp.watch('./js-app/*/*/*.js', ['browserify', 'uglify']);
    //gulp.watch('./js-app/sales/controllers/*.js', ['browserify', 'uglify']);
    //gulp.watch('./js-app/sales/*.js', ['browserify', 'uglify']);
    //
    //gulp.watch('./js-app/admin/controllers/*.js', ['browserify', 'uglify']);
    //gulp.watch('./js-app/admin/*.js', ['browserify', 'uglify']);
    //
    //gulp.watch('./js-app/common/*.js', ['browserify', 'uglify']);
    //gulp.watch('./js-app/misc/*.js', ['browserify', 'uglify']);
    //
    //gulp.watch('./js-app/*.js', ['browserify', 'uglify']);
    //
    //gulp.watch('./js-app/directives/*.js', ['browserify', 'uglify']);
    gulp.watch('./www/inventory/controllers/*.js', ['browserify', 'uglify']);
    gulp.watch('./js-app/inventory/*/*.js', ['browserify', 'uglify']);
    gulp.watch('./js-app/inventory/*/*/*.js', ['browserify', 'uglify']);
});
gulp.task('default',['browserify','uglify','watch']);


